<!--职称申报学历表单-->
<template>
  <div class="form">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left" class="label required">入学时间</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择入学时间'}]"
          v-model="form.aae030"
          ref="aae030"
          placeholder="请选择入学时间"
          :endDate="new Date()"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">毕业时间</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择毕业时间'}]"
          v-model="form.aac046"
          ref="aac046"
          placeholder="请选择毕业时间"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">毕业院校</span>
        <xf-input
          slot="right"
          :valid="[{required: true, msg: '请输入毕业院校'}]"
          v-model="form.aac045"
          ref="aac045"
          placeholder="请输入毕业院校"></xf-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label">所学专业：</span>
        <xf-picker
              slot="right"
              :valid="[{required: true, msg: '请选择所学专业'}]"
              v-model="form.acc01g"
              ref="acc01g"
              :list="profession"
              placeholder="请选择所学专业"></xf-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label">学历：</span>
        <xf-picker
            slot="right"
            :valid="[{required: true, msg: '请选择学历'}]"
            v-model="form.atc011"
            ref="atc011"
            :list="edu"
            placeholder="请选择学历"></xf-picker>
      </yd-cell-item>
    </yd-cell-group>
    <div class="right-bottom">
      <mt-button type="default" size="small" @click="cancel">取消</mt-button>
      <mt-button type="primary" size="small" @click="onSubmit">保存</mt-button>
    </div>
  </div>
</template>
<script>
  import XfDatePicker from '../../../components/xf-date-picker/xf-date-picker.vue'
  import XfInput from '../../../components/xf-input/xf-input.vue'
  import XfPicker from '../../../components/xf-picker/xf-picker.vue'
  import {dics, getDics} from '../../../common/js/dictionaries'
  import {validate} from '../../../common/js/util'
  export default {
    props: {
      code: {type: null, default: ''}
    },
    components: {
      XfPicker,
      XfInput,
      XfDatePicker},
    name: 'title-form-edu',
    data() {
      return {
        edu: [], // 学历字典表
        profession: [], // 专业字典表
        form: {
          aac045: '', // 大学名称
          aae030: '', // 入学时间
          aac046: '', // 毕业时间
          acc01g: '', // 专业
          atc011: ''// 学历
        }
      }
    },
    methods: {
      getDics() {
        getDics(dics.edu, dics.profession).then(res => {
          this.edu = res[0]
          this.profession = res[1]
        })
      },
      cancel() {
        this.$emit('cancel')
      },
      onSubmit() {
        validate.bind(this)(this.form).then(() => {
          var list = []
          if (sessionStorage.getItem('titleEducation')) {
            list.push(sessionStorage.getItem('titleEducation'))
            list.push(JSON.stringify(this.form))
            window.sessionStorage.setItem('titleEducation', list)
          } else {
            window.sessionStorage.setItem('titleEducation', JSON.stringify(this.form))
          }
          this.$emit('cancel')
        }).catch(err => {
          console.log(err)
        })
      }
    },
    created() {
      this.getDics()
    }
  }
</script>
